package com.piggy.logi.sys.controller;

import java.util.List;
import java.util.Arrays;

import com.piggy.common.log.annotation.LogiLog;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import com.piggy.common.log.annotation.Log;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.logi.sys.vo.LogiPickupWaybillVo;
import com.piggy.logi.sys.bo.LogiPickupWaybillQueryBo;
import com.piggy.logi.sys.bo.LogiPickupWaybillEditBo;
import com.piggy.logi.sys.service.ILogiPickupWaybillService;
import com.piggy.common.core.utils.poi.ExcelUtil;
import com.piggy.common.core.web.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.piggy.common.core.domain.R;
import java.lang.Integer;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
 * 提货单运单关联关系Controller
 *
 * @author piggy
 * @date 2023-08-25
 */
@Api(value = "提货单运单关联关系控制器", tags = {"提货单运单关联关系管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/pickupwaybill")
public class LogiPickupWaybillController extends BaseController {

    private final ILogiPickupWaybillService iLogiPickupWaybillService;

    /**
     * 查询提货单运单关联关系列表
     */
    @ApiOperation("查询提货单运单关联关系列表")
    //@SaCheckPermission("sys:pickupwaybill:list")
    @GetMapping("/list")
    public TableDataInfo<LogiPickupWaybillVo> list(@Validated LogiPickupWaybillQueryBo bo) {
        return iLogiPickupWaybillService.queryPageList(bo);
    }

    /**
     * 导出提货单运单关联关系列表
     */
    @ApiOperation("导出提货单运单关联关系列表")
    //@SaCheckPermission("sys:pickupwaybill:export")
    @LogiLog(title = "提货单运单关联关系", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated LogiPickupWaybillQueryBo bo, HttpServletResponse response) throws IOException {
        List<LogiPickupWaybillVo> list = iLogiPickupWaybillService.queryList(bo);
        ExcelUtil<LogiPickupWaybillVo> util = new ExcelUtil<LogiPickupWaybillVo>(LogiPickupWaybillVo.class);
        util.exportExcel(response, list, "提货单运单关联关系");
    }

    /**
     * 获取提货单运单关联关系详细信息
     */
    @ApiOperation("获取提货单运单关联关系详细信息")
    //@SaCheckPermission("sys:pickupwaybill:query")
    @GetMapping("/{id}")
    public R<LogiPickupWaybillVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return R.ok(iLogiPickupWaybillService.queryById(id));
    }

    /**
     * 新增提货单运单关联关系
     */
    @ApiOperation("新增提货单运单关联关系")
    //@SaCheckPermission("sys:pickupwaybill:add")
    @LogiLog(title = "提货单运单关联关系", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<LogiPickupWaybillVo> add(@Validated @RequestBody LogiPickupWaybillEditBo bo) {
        return R.ok(iLogiPickupWaybillService.insertByAddBo(bo));
    }

    /**
     * 修改提货单运单关联关系
     */
    @ApiOperation("修改提货单运单关联关系")
    //@SaCheckPermission("sys:pickupwaybill:edit")
    @LogiLog(title = "提货单运单关联关系", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<LogiPickupWaybillVo> edit(@Validated @RequestBody LogiPickupWaybillEditBo bo) {
        return R.ok(iLogiPickupWaybillService.updateByEditBo(bo));
    }

    /**
     * 删除提货单运单关联关系
     */
    @ApiOperation("删除提货单运单关联关系")
    //@SaCheckPermission("sys:pickupwaybill:remove")
    @LogiLog(title = "提货单运单关联关系" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Integer> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return R.ok(iLogiPickupWaybillService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
